﻿#ifndef Archer_Arrow_h
#define Archer_Arrow_h

#include "ArcherBase.h"

#include "cocos2d.h"

#include <list>

// 箭矢信息
struct ArrowInfo
{
	float _mass;            // 质量
	float _gravity;         // 重力加速度
	float _windPower;       // 风力
	bool  _bUseFrame;       // 是否使用frame加载
	float _arrowWidth;      // 箭矢长度（从头部到握点）
	char  _fileName[64];    // 文件名

	ArrowInfo()
	{
		_mass = 2.0f;
		_gravity = 1000;
		_windPower = 0;
		_bUseFrame = false;
		_fileName[0] = 0;
		_arrowWidth  = -1;
	}
};

class CArrow : public CArrowBase
{
public:
	static CArrow *CreateArrow(const ArrowInfo &info, cocos2d::CCNode *pParent, int zOrder = 0);
public:
	CArrow()
		: m_pSprArrow(NULL)
	{
	}

	void             Remove();

	float            GetCurAngle() {return m_curAngle;}
	float            GetCurRad()   {return CC_DEGREES_TO_RADIANS(m_curAngle);}
    cocos2d::CCSprite *GetSprite() {return m_pSprArrow;}

	cocos2d::CCPoint TailToHead(cocos2d::CCPoint ptTail, float angle);
	void Shoot(float power, cocos2d::CCPoint ptHead, float angle, list<CArcherBase *> *pTargetList);

	// 调整位置阶段，根据手的位置与角度调整箭位置
	void Prepare(cocos2d::CCPoint ptTail, float angle);

	// 根据时间，来定位弓箭，弓箭射出时为0
	bool ProcessTime(float time);

private:
	// 初始化
	void _InitState(const char *szFileName, cocos2d::CCNode *pParent, bool bUseFrame, int zOrder);

private:
	cocos2d::CCSprite *m_pSprArrow;

	float              m_curAngle;      // 当前图片旋转角度，笛卡尔坐标系
};

class CArrowManager
{
public:
    static const ArrowInfo &GetArrowInfo(int id);
    
};
#endif
